﻿using System;
using System.Collections.Generic;
using System.Linq;
using ApiScanner.Core;

namespace ApiScannerShell.ViewModels
{
    public sealed class ServerNameConfigurationElementCollectionViewModel : ViewModelCollection<ServerNameConfigurationElementViewModel, ServerNameConfigurationElement>
    {
        public ServerNameConfigurationElementCollectionViewModel(ServerNameConfigurationElementCollection servers): base(servers)
        {
        }

        protected override ServerNameConfigurationElementViewModel CreateViewModel(ServerNameConfigurationElement model)
        {
            return new ServerNameConfigurationElementViewModel(model);
        }

        public void Add(string serverName)
        {
            if (string.IsNullOrEmpty(serverName)) throw new ArgumentNullException("serverName");
            if (this.Any(model => model.Name.Equals(serverName, StringComparison.OrdinalIgnoreCase))) return;
            AddItem(new ServerNameConfigurationElementViewModel(new ServerNameConfigurationElement { Name = serverName}));
        }

        public void Clear()
        {
            ClearItems();
        }

        public void Remove(IEnumerable<ServerNameConfigurationElementViewModel> items)
        {
            items = items.ToArray();
            foreach (var item in items)
            {
                RemoveItem(item);
            }
        }
    }
}